import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

// 需要左方向动画的路由用this.$router.to('****')
VueRouter.prototype.togo = function (path, par) {
  this.isleft = true
  this.isright = false
  this.push({
    path: path,
    query: par
  })
}
// 跳转指定url路径，但是history栈中不会有记录，点击返回会跳转到上上个页面 (就是直接替换了当前页面)，传参跟push一样
VueRouter.prototype.toReplace = function (path, par) {
  this.isleft = true
  this.isright = false
  this.replace({
    path: path,
    query: par
  })
}
// 需要返回按钮动画的路由用this.$router.goBack()，返回上一个路由
VueRouter.prototype.goBack = function (n) {
  this.isright = true
  this.isleft = false
  this.go(n || -1)
}
// 点击浏览器返回按钮执行，此时不需要路由回退
VueRouter.prototype.togoback = function () {
  this.isright = true
  this.isleft = false
}

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home,
  },
  {
    path: "/about",
    name: "About",
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ "../views/About.vue"),
  },
];

const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

export default router;
